using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Objects;
using System.Linq;
using System.Linq.Expressions;
using System.Data.EntityClient;
using SQLServerCompactEdition.Repository.DAL.RepositoryDao;
using SQLServerCompactEdition.Repository.POCO.Generated;

namespace SQLServerCompactEdition.Repository.DAL
{
    
    #region License
    // <copyright file="FournisseurDao.cs" company="Kopigi - Marc Plessis">
    // Copyright © Kopigi 2011
    // </copyright>
    // ****************************************************************************
    // <author>Marc Plessis</author>
    // <email>marc.plessis@kopigi.fr</email>
    // <date>03/04/2011</date>
    // <project>Biwo</project>
    // <web>http://www.kopigi.fr/biwo</web>
    // <license>
    // See license.txt in this solution or http://www.microsoft.com/opensource/licenses.mspx
    // </license>
    #endregion
    
    public static class FournisseurDao
    {
    	#region Initialize Context
    	private static IRepository<Fournisseur> _context;
    	private static IRepository<Fournisseur> GetSingleton()
    	{
            return _context ?? (typeof(Fournisseur).IsSubclassOf(typeof(Personne)) ? _context = new RepositorySubOjectEntity<Personne, Fournisseur>() : _context = new Repository<Fournisseur>());
    	}
    	
    	/// <summary>
        /// Unique ObjectContext by RepositoryDao
        /// </summary>
        /// <param name="proxyAndLazyLoadingEnabled">Set ProxyCreationEnabled and LazyLoadingEnabled, default as true</param>
    	public static void InitializeConnectionForRepository(bool proxyAndLazyLoadingEnabled)
    	{
    		var newContext = new BiwoSampleContainer();
    		_context = new Repository<Fournisseur>(newContext, proxyAndLazyLoadingEnabled);
    	}
    	
    	/// <summary>
        /// Unique ObjectContext by RepositoryDao
        /// </summary>
    	/// <param name="connectionString">ConnectionString Name</param>
        /// <param name="proxyAndLazyLoadingEnabled">Set ProxyCreationEnabled and LazyLoadingEnabled, default as true</param>
    	public static void InitializeConnectionForRepository(bool proxyAndLazyLoadingEnabled, string connectionString)
    	{
    		var newContext = new BiwoSampleContainer("name=" + connectionString);
    		_context = new Repository<Fournisseur>(newContext, proxyAndLazyLoadingEnabled);
    	}
    	
    	/// <summary>
        /// Unique ObjectContext by RepositoryDao
        /// </summary>
    	/// <param name="connection">EntityConnection to context</param>
        /// <param name="proxyAndLazyLoadingEnabled">Set ProxyCreationEnabled and LazyLoadingEnabled, default as true</param>
    	public static void InitializeConnectionForRepository(bool proxyAndLazyLoadingEnabled, EntityConnection connection)
    	{
    		var newContext = new BiwoSampleContainer(connection);
    		_context = new Repository<Fournisseur>(newContext, proxyAndLazyLoadingEnabled);
    	}
    	
    	/// <summary>
        /// Set unique context to all RepositoryDao
        /// </summary>
        /// <param name="context">Unique ObjetContext to all RepositoryDao</param>
    	/// <param name="proxyAndLazyLoadingEnabled">Set ProxyCreationEnabled and LazyLoadingEnabled, default as true</param>
        public static void SetContext(ObjectContext context, bool proxyAndLazyLoadingEnabled = false)
        {
            _context = new Repository<Fournisseur>(context, proxyAndLazyLoadingEnabled);
        }
    
        /// <summary>
        /// Unique ObjectContext by RepositoryDao
        /// </summary>
        public static void ReInitializedUniqueContextForRepository()
        {
            _context = null;
        }
    	
    	
    	#endregion
    	
    	/// <summary>
        /// Adds the specified entity
        /// </summary>
        /// <param name="entity">Entity to add</param>
    	/// <param name="prefixPrimaryKey">Object prefix for value of PrimaryKey</param>
        /// <exception cref="ArgumentNullException"> if <paramref name="entity"/> is null</exception>
    	public static void Add(Fournisseur entity, object prefixPrimaryKey = null)
    	{
    		GetSingleton().Add(entity, prefixPrimaryKey);
    	}
    	
    	 /// <summary>
        /// Attaches the specified entity
        /// </summary>
        /// <param name="entity">Entity to attach</param>
    	public static void Attach(Fournisseur entity)
    	{
    		GetSingleton().Attach(entity);
    	}
    	
    	/// <summary>
        /// Deletes the specified entitiy
        /// </summary>
        /// <param name="entity">Entity to delete</param>
        /// <exception cref="ArgumentNullException"> if <paramref name="entity"/> is null</exception>
    	public static void Delete(Fournisseur entity)
    	{
    		GetSingleton().Delete(entity);
    	}
    	
    	/// <summary>
        /// Deletes records matching the specified criteria
        /// </summary>
        /// <param name="predicate">Criteria to match on</param>
        public static void Delete(Expression<Func<Fournisseur, bool>> predicate)
        {
    		GetSingleton().Delete(predicate);
    	}
    	
        /// <summary>
        /// Deletes all records
        /// </summary>
        public static void DeleteAll()
        {
            GetSingleton().DeleteAll();
        }
    
    	/// <summary>
        /// Gets all records as an IQueryable
        /// </summary>
        /// <returns>An IQueryable object containing the results of the query</returns>
    	public static IQueryable<Fournisseur> Fetch()
    	{
    		return GetSingleton().Fetch();
    	}
    	
    	/// <summary>
        /// The first record matching the specified criteria
        /// </summary>
        /// <param name="predicate">Criteria to match on</param>
        /// <returns>A single record containing the first record matching the specified criteria</returns>
    	public static Fournisseur First(Expression<Func<Fournisseur, bool>> predicate)
    	{
    		return GetSingleton().First(predicate);
    	}
    	
    	/// <summary>
        /// Gets all records as an IEnumberable
        /// </summary>
        /// <returns>An IQueryable object containing the results of the query</returns>
    	public static IQueryable<Fournisseur> GetAll()
    	{
    		return GetSingleton().GetAll();
    	}
    	
    	/// <summary>
        /// Get entity by id
        /// </summary>
        /// <param name="id">id to load entity</param>
    	/// <param name="searchInEntitiesUnSaving">Include search into entities not saving yet</param>
        /// <returns>T entity</returns>
    	public static Fournisseur GetById(object id)
    	{
    		return GetSingleton().GetById(id);
    	}
    	
    	///<summary>
    	/// Get entities filter by an EntityState
    	///</summary>
    	/// <param name="entity">EntityState to filter</param>
        /// <returns>List of entities</returns>
        public static IEnumerable<ObjectStateEntry> GetObjectStateEntry(EntityState stateFilter)
    	{
    		return GetSingleton().GetObjectStateEntry(stateFilter);
    	}
    	
    	///<summary>
    	/// Get state of an entity
    	///</summary>
    	/// <param name="entity">Entity to search</param>
        /// <returns>EntityState</returns>
     	public static EntityState GetEntityState(Fournisseur entity)
    	{
    		return GetSingleton().GetEntityState(entity);
    	}
    	
    	/// <summary>
        /// Check if entity is new
        /// </summary>
        /// <param name="entity">entity to check</param>
        /// <returns>boolean</returns>
    	public static bool IsNew(Fournisseur entity)
    	{
    		return GetSingleton().IsNew(entity);
    	}
    	
    	/// <summary>
        /// Save entity
        /// </summary>
        /// <param name="entity">Entity to save</param>
    	/// <param name="prefixPrimaryKey">Object prefix for value of PrimaryKey</param>
        public static Fournisseur Save(Fournisseur entity, object prefixPrimaryKey = null)
    	{
    		return GetSingleton().Save(entity, prefixPrimaryKey);
    	}
    	
    	/// <summary>
        /// Saves all context changes
        /// </summary>
        public static int SaveChanges()
    	{
    		return GetSingleton().SaveChanges();
    	}
    	
    	/// <summary>
        /// Gets a single record by the specified criteria (usually the unique identifier)
        /// </summary>
        /// <param name="predicate">Criteria to match on</param>
        /// <returns>A single record that matches the specified criteria</returns>
    	public static Fournisseur Single(Expression<Func<Fournisseur, bool>> predicate)
    	{
    		return GetSingleton().Single(predicate);
    	}
    	
    	/// <summary>
        /// Find records with the specified criteria
        /// </summary>
        /// <param name="predicate">Criteria to match on</param>
        /// <returns>A collection containing the results of the query</returns>
    	public static IQueryable<Fournisseur> Where(Expression<Func<Fournisseur, bool>> predicate)
    	{
    		return GetSingleton().Where(predicate);
    	}
    	
    	/// <summary>
        /// Releases all resources used by the context
        /// </summary>
        public static void Dispose()
        {
    		GetSingleton().Dispose();
    	}
    }
}
